package com.example.usedemo.controller;

import com.example.usedemo.dao.UserMapper;
import com.example.usedemo.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserMapper userMapper;

    @GetMapping("{id}")
    public User get(@PathVariable("id") String id){
        return userMapper.findById(id);
    }

    @PostMapping("login")
    public HashMap<String ,Object> login(@RequestBody User user) {
        HashMap<String ,Object> map=new HashMap<>();
        User userInfo=userMapper.findByNameAndPassword(user);
        if (userInfo==null){
            logger.info("no such user");
            map.put("info","no such user");
        }else {
            logger.info("login successfully");
            map.put("info","login Successfully");
            map.put("userInfo",userInfo);










        }
        return map;
    }

    @GetMapping("test0")
    public User gete2(){
        User user=new User();
        user.setId("ss");
        user.setName("fbz");
        user.setPassword("12456");
        Class clazz=UserController.class;
        logger.info("包括注解:{}", Arrays.toString(clazz.getDeclaredAnnotations()));
//        logger.info("是否包含:{}",clazz.getAnnotation(org.springframework.stereotype.Component.class));
//        加了一个declared就会只有本类的方法 不加就会包括父类的方法
        Annotation[] annotations=clazz.getAnnotations();
        for(Annotation annotation:annotations){
            logger.info("注解有:{}",annotation);
        }
        return user;


    }
}
